<%@ page language="java" pageEncoding="utf-8" contentType="text/html; charset=utf-8"%>
<%@ include file="../include/taglib.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head> 
  	<title>优惠管理</title>
  	<%@ include file="../include/jsCss.jsp" %>
  </head>
  
  <body>
  	<form action="preferential!preferentialList.html" method="post" id="frmSelectPreferential">
		优惠管理
		<hr />
		<table width="130%">
			<tr>
				<td>优惠名称</td>
				<td><input type="text" name="name"/></td>  
				<td><input type="button" value="搜索" onclick="javascript:btnSelectPreferential();"/></td>
				<td style="text-align: right;">
					<a href="javascript:;" onclick="releasePreferential(true)">发布优惠</a>
					<a href="javascript:;" onclick="releasePreferential(false);">取消发布</a>
					<a href="preferential!preferentialAdd.html">添加优惠</a>	
				</td>
			</tr>
		</table>

		<table width="130%" border="1">
			<tr>
				<td rowspan="1" ><input type="checkbox" name="CheckBoxAll" onclick="checkedAll(this)"/></td>
				<td>优惠名称</td>  
				<td>原价</td>
				<td>优惠价</td>
				<td>折扣幅度</td>
				<td>开始日期</td>
				<td>结束日期</td> 
				<td>优惠份数</td>
				<td>优惠介绍</td> 
				<td>发布状态</td>
				<td>状态</td>
				<td>操作</td>
			</tr>
			<s:iterator value="preferentialDtoList">
				<tr>
					<td>
						<input type="checkbox" name="releaseCheckBox" value="${id}"/>
					</td>
					<td>
						${name}
					</td> 
				 
					<td>
						${costPrice}
					</td>
					<td>
						${preferentialPrice }
					</td>
					<td>
						${discount }
					</td>
					<td>
						${beginDate }
					</td>
					<td>
						${endDate }
					</td> 
					<td>${copies } </td>
					<td>${explanation }</td> 
					<td>
						<s:if test="releaseStatus == true">
							已发布
						</s:if>
						<s:else>
							未发布
						</s:else> 
					</td>
					<td>
						<s:if test="status == 0">
							审核中
						</s:if>
						<s:if test="status == 1">
							审核通过
						</s:if>
						<s:if test="status == 2">
							审核不通过
						</s:if>
						<s:if test="status == 3">
							作废
						</s:if>
					</td>
					<td><a href="preferential!preferentialUpdate.html?id=${id }">修改</a></td>
				</tr>
			</s:iterator>
		</table>
		<div>
			<jsp:include page="../include/page.jsp"></jsp:include> 
		</div>
	</form>
     <script type="text/javascript">
     		//发布和取消发布
			function releasePreferential(status) {
				var preferentialIds = ""; 
				$("input[name='releaseCheckBox']").each(function(i,item){
					 if (item.checked == true) {
						 preferentialIds += item.value + ",";
					 }
				});
				 
				if (preferentialIds == "") {
					alert("请选择要发布的优惠!");
					return;
				}
				preferentialIds = preferentialIds.substring(0, preferentialIds.length-1);
				var dt = new Date();
				$.ajax( {
					type : "POST",
					url : "preferential!release.html",
					data : "preferentialIds="+preferentialIds+"&releaseStatus="+status+"&date=" + dt,
					success : function(data) {
						if ($.trim(data) == 0) {
							if (status == true) { 
								alert('发布成功!');
							}
							if (status == false) {
								alert('取消发布成功');
							}
							document.location.reload();
						} else {
							alert('操作失败!');
						}
					}
				}); 
			}
     		
     		function btnSelectPreferential(){
     			$("#frmSelectPreferential").submit();
     		}
     </script>
  </body>
</html>
